package com.jian.ecommercial.controller;

import com.github.pagehelper.PageInfo;
import com.jian.ecommercial.domain.Stock;
import com.jian.ecommercial.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@RestController
@CrossOrigin
@RequestMapping("/stocks")
public class StockController extends BaseController{
    @Autowired
    private StockService stockService;

    @RequestMapping("/list")
    public PageInfo<Stock> getStockLists(Integer pageNum,String todayDate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String pt_date = sdf.format(new Date(Long.parseLong(todayDate)));
        System.out.println("...."+pageNum+"...."+todayDate+"...."+pt_date);
        if (pageNum == null){
            pageNum = 0;
        }
        PageInfo<Stock> stockPageInfo = stockService.list(pageNum,pt_date);
        return stockPageInfo;
    }
}
